import requests from "@/api/request.js";
import axios from "axios";
import {host_custom} from "@/host.js";

export const fetchMsgApi = (chat_id, msgOffset) => requests({
    url: '/getMsg',
    method: 'GET',
    params: {chat_id, msgOffset}
})

export const getUserConversationsApi = (uid) => requests({
    url: '/getConversations',
    method: 'GET',
    params: {uid}
})

export const getInboxRequestApi = (uid) => requests({
    url: '/getFriendRequest',
    method: 'GET',
    params: {uid}
})

export const getInboxApi = (uid) => requests({
    url: '/getInbox',
    method: 'GET',
    params: {uid}
})

export const fetchMoreMsgApi = (msgOffset, groupId) => requests({
    url: '/getMoreMsg',
    method: 'GET',
    params: { msgOffset, roomNumber: groupId}
})

export const sendMsgApi = (formData, onUploadProgress) => requests({
    url: '/sendMsg',
    method: 'POST',
    data: formData,
    headers: {'Content-Type': 'multipart/form-data'},
    timeout: 300000,
    maxBodyLength: 100*1024*1024,
    maxContentLength: 100*1024*1024,
    onUploadProgress: onUploadProgress
})

export const editMsgApi = (msgId, content) => requests({
    url: '/updateMsg',
    method: 'PATCH',
    data: {msgId, content},
})

export const deleteMsgApi = (msgId) => requests({
    url: '/deleteMsg',
    method: 'DELETE',
    data: {msgId},
})

export const getDmOppUserApi = (conId, uid) => requests({
    url: '/getDmOppUser',
    method: 'GET',
    params: {conId, uid}
})

